package com.xh.cdp.sys.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import com.xh.cdp.common.util.DateUtil;
import com.xh.cdp.common.util.MD5Util;

@Entity
@Table(name = "sys_user")
@DynamicUpdate
@DynamicInsert
public class SysUserEntity {
	// 循环设置属性
	@Id
	@GeneratedValue(generator = "myUuid")
	@GenericGenerator(name = "myUuid", strategy = "uuid")
	private String id;

	@Column(name = "password")
	private String password;

	@Column(name = "code")
	private String code;

	@Column(name = "name")
	private String name;

	@Column(name = "state")
	private Integer state;

	@Column(name = "register_time")
	private Date registerTime;

	@Transient
	private String roleId;
	@Transient
	private String roleName;
	// 构造方法
	public SysUserEntity() {
		super();
	}

	// 循环设置 set()、get()

	public void setPassword(String password) {
		this.password = MD5Util.md5(password);
	}

	public SysUserEntity(String password) {
		super();
		this.password = password;
	}

	public String getPassword() {
		return this.password;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getCode() {
		return this.code;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return this.name;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getId() {
		return this.id;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	public Integer getState() {
		return this.state;
	}

	public String getRegisterTimeFormat() {
		if (registerTime != null)
			return DateUtil.format(registerTime, "yyyy-MM-dd HH:mm:ss");
		return null;
	}

	public Date getRegisterTime() {
		return registerTime;
	}

	public void setRegisterTime(Date registerTime) {
		this.registerTime = registerTime;
	}

	public String getRoleId() {
		return roleId;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String getStateName() {
		if(state == 1) {
			return "有效";
		} else if(state == 2) {
			return "无效";
		}
		return "未知";
	}

	public SysUserEntity(String id, String code, String name, Integer state,
			Date registerTime, String roleId, String roleName) {
		super();
		this.id = id;
		this.code = code;
		this.name = name;
		this.state = state;
		this.registerTime = registerTime;
		this.roleId = roleId;
		this.roleName = roleName;
	}

	public SysUserEntity(String id, String code, String password, String name,
			Integer state, Date registerTime, String roleId, String roleName) {
		super();
		this.id = id;
		this.code = code;
		this.password = password;
		this.name = name;
		this.state = state;
		this.registerTime = registerTime;
		this.roleId = roleId;
		this.roleName = roleName;
	}

	@Override
	public String toString() {
		return "SysUserEntity [id=" + id + ", password=" + password + ", code="
				+ code + ", name=" + name + ", state=" + state
				+ ", registerTime=" + registerTime + ", roleId=" + roleId
				+ ", roleName=" + roleName + ", stateName=" + getStateName() + "]";
	}

}
